<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <script th:src="@{/layui/layui.js}" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
</head>
<body>


<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>修改教学计划</legend>
</fieldset>

<form class="layui-form" action="" id="editForm">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">上课日期</label>
            <div class="layui-input-inline">
                <input type="hidden" name="teach_id" th:value="${teach.teach_id}">
                <input type="text" name="date" id="order_date" th:value="${teach.date}" lay-verify="date" placeholder="yyyy-MM-dd"
                       autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">课程</label>
            <div class="layui-input-inline">
                <input type="text" name="course" th:value="${teach.course}" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>

    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">第一节课</label>
            <div class="layui-input-inline">
                <input type="text" name="one" th:value="${teach.one}"autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">第二节课</label>
            <div class="layui-input-inline">
                <input type="text" name="two" th:value="${teach.two}"autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">第三节课</label>
            <div class="layui-input-inline">
                <input type="text" name="three"th:value="${teach.three}" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">第四节课</label>
            <div class="layui-input-inline">
                <input type="text" name="four" th:value="${teach.four}"lay-verify="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">第五节课</label>
            <div class="layui-input-inline">
                <input type="text" name="five"th:value="${teach.five}" lay-verify="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">第六节课</label>
            <div class="layui-input-inline">
                <input type="text" name="six"th:value="${teach.six}" lay-verify="" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">第七节课</label>
            <div class="layui-input-inline">
                <input type="text" name="seveen" th:value="${teach.seveen}"lay-verify="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">第八节课</label>
            <div class="layui-input-inline">
                <input type="text" name="eight"th:value="${teach.eight}" lay-verify="" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <input type="text" name="remark" th:value="${teach.remark}"lay-verify="" autocomplete="off" class="layui-input">
            </div>
        </div>

    </div>
    <div class="layui-form-item">
        <button type="button" onclick="doSave();" class="layui-btn" lay-submit="" lay-filter="demo2">更新</button>
    </div>


</form>

<script>
    var $, layer;
    layui.use(['form', 'laydate'], function () {
        var laydate = layui.laydate;
        layer = layui.layer;
        $ = layui.jquery;//拿到jQuery对象
        laydate.render({
            elem: '#order_date'
            , trigger: 'click'//解决日期一闪而过

        })

    })

    function doSave() {
        //发送post请求
//         语法：$.post(url,data,callback,type);
//         url(必须):发送请求的地址，String类型
//         data(可选):发送给后台的数据，以key/value形式{a:value1,b:value2}，即json格式
//         callback(可选):请求成功后的回调函数。因此，在后台的处理中，需要给JSONObject put一个是否成功的值
//         type(可选):即第二个参数data的数据类型。如果有data传递给后台，则需要加上该类型
        var requestData = $("#editForm").serialize();//拿到表单数据
        $.ajax({
            type: 'POST',
            url: "/teach/save",
            data: requestData,
            success: function (responseData) {
                layer.alert("修改成功", {
                    yes: function () {
                        //页面由谁弹出来的就由谁关掉，index
                        parent.layer.closeAll();
                    }
                })
            },
            error: function () {

            },
            dataType: "json"
        })
    }
</script>

</body>
</html>